from ConfigParam import *
import jaydebeapi
import os


def tosql1():
    a = os.getcwd()
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    conn1 = jaydebeapi.connect(databases1["jclassname"], databases1["url"], databases1["driver_args"],
                               databases1["jars"])
    cursor1 = conn1.cursor()
    os.chdir(a)
    return [conn1, cursor1]


def tosql2():
    a = os.getcwd()
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    conn2 = jaydebeapi.connect(databases2["jclassname"], databases2["url"], databases2["driver_args"],
                               databases2["jars"])
    cursor2 = conn2.cursor()
    os.chdir(a)
    return [conn2, cursor2]


def tosql3():
    a = os.getcwd()
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    conn3 = jaydebeapi.connect(databases3["jclassname"], databases3["url"], databases3["driver_args"],
                               databases3["jars"])
    cursor3 = conn3.cursor()
    os.chdir(a)
    return [conn3, cursor3]


def UPDATESql(date):
    sql = "UPDATE tb_jrsj SET jrsj_jxstorestatus = 1 AND jrsj_filestorestatus = 1 WHERE jrsj_id = %s " % (date)
    return sql


def INSERTSql(date):
    sql = "INSERT INTO %s(%s,%s,%s,%s,%s) VALUES ('%s', '%s', '%s', '%s', '%s')" % (
        date['table'], date['field1'], date['field2'], date['field3'], date['field4'], date['field5'], date['value1'],
        date['value2'], date['value3'], date['value4'], date['value5'])
    return sql


def INSERT_geojson(date):
    sql = "INSERT INTO tb_gdfs%s_geojson(gdfs%s_geojson_time,gdfs%s_geojson_content,gdfs%s_geojson_jrsjid) VALUES ('%s', '%s', '%s')" % (
        date["geoJsonTableName"].lower(), date["geoJsonTableName"], date["geoJsonTableName"], date["geoJsonTableName"],
        date["time"], date["geojson"], date["jrsjid"])
    return sql


def INSERT_ocfgeojson(date):
    sql = "INSERT INTO tb_ocf_geojson(ocf_geojson_time,ocf_geojson_content,ocf_geojson_jrsjid) VALUES ('%s', '%s', '%s')" % (
        date["time"], date["geojson"], date["jrsjid"])
    return sql
def INSERT_lapsGeojson(date):
    sql = "INSERT INTO tb_laps_geojson_%s(laps_geojson_time, laps_geojson_content, laps_geojson_jrsjid) VALUES ('%s', '%s', '%s')"%(
        date["geoJsonTableName"].lower(),date["time"],date["geojson"],date["jrsjid"])
    return sql


def INSERT_lapsGeojson(date):
    sql = "INSERT INTO tb_laps_geojson_%s(laps_geojson_time, laps_geojson_content, laps_geojson_jrsjid) VALUES ('%s', '%s', '%s')"%(
        date["geoJsonTableName"].lower(),date["time"],date["geojson"],date["jrsjid"])
    return sql